#include <stdio.h>
#include <stdlib.h>

typedef enum { false, true } bool;
typedef int ElemSet; /* 默认矩阵元素为整型 */
#define kMaxPeople 3
#define kMaxBook 4
typedef struct MatrixNode *Matrix;
struct MatrixNode {
    ElemSet t[kMaxPeople][kMaxBook];
    int row;
    int col;
};

bool Check(int s1, int s2, int s3, Matrix T) {
    bool ret;

    /* 检查约束条件（1）：不同的人分到不同的书 */
    ret = (s1 != s2 && s2 != s3 && s3 != s1);

    /* 检查约束条件（2）：第i个人喜欢第si本书 */
    /* 数组下标从0开始，所以书的编号要减1 */
    ret = ret && (T->t[0][s1 - 1] == 1
    && T->t[1][s2 - 1] == 1
    && T->t[2][s3 - 1] == 1);

    return ret;
}

/* 算法15-1：小规模分书问题的嵌套循环算法 BookAssignment(T) */
void BookAssignment(Matrix T) {
    /* 3人分4本书 */
    int s1, s2, s3;

    for (s1 = 1; s1 <= 4; s1++) {
        for (s2 = 1; s2 <= 4; s2++) {
            for (s3 = 1; s3 <= 4; s3++) {
                if (Check(s1, s2, s3, T) == true) {
                    printf("(%d, %d, %d)\n", s1, s2, s3);
                }
            }
        }
    }
}
/* 算法15-1 结束 */

int main(void) {
    Matrix T;
    int n_people, n_book, i, j;

    scanf("%d %d", &n_people, &n_book);
    T = (Matrix)malloc(sizeof(struct MatrixNode));
    T->row = n_people;
    T->col = n_book;
    for (i = 0; i < n_people; i++) {
        for (j = 0; j < n_book; j++) {
            scanf("%d", &T->t[i][j]);
        }
    }
    BookAssignment(T);
    free(T);

    return 0;
}